<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta http-equiv="Access-Control-Allow-Origin" content="*">
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <title>props</title>
</head>

<body>
  <div id="app">
    <h1>Chapter 2</h1>  
    <input-username :value="username" @input="value=>username=value"></input-username>
    <p>username:{{username}}</p>
  </div>
  <script>
    Vue.component('input-username', {
      template: '<input type="text" :value="value" @input="handleInput">',
      props: {
        value: {
          type: String,
          required: true,
        }
      }, 
      methods:{
        handleInput(e){
          const value=e.target.value.toLowerCase();
          if(value!== e.target.value){
            e.target.value=value;
          }
          this.$emit('input',value);
        }
      } 
    });
    new Vue({
      el: '#app',
      data:{
        username:''
      } 
    });
  </script>
</body>

</html>